home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ShareWare OnLine 2
/
ShareWare OnLine Volume 2 (CMS Software)(1993).iso
/
games2
/
rotise12.zip
/
STENOG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-03
|
9KB
|
352 lines
/* Stenog.c
Jonathan Arnold 1991
Do all the secretarial and file functions, like:
comment - insert a comment
cost - describe the transaction costs
interval - read in the statistics data file to begin an interval
opsof - read in the old position file
slot - describe slots on the teams
bstats - list the statistics used for batters
pstats - list the statistics used for pitchers
salunit - how many pennies in a salary unit
*/
#include <stdio.h>
#include <string.h>
#include "rotise.h"
#ifdef __TURBOC__
#include <stdlib.h>
#include <io.h>
#include <alloc.h>
#endif
/* External data referenced */
extern CMDLIST CmdTable[]; /* cmdtable.c */
extern int Cmd; /* rotise.c */
extern int InputLine; /* Line # of current file */
extern BOOL Verbose; /* How talkative to be */
extern char *InputFilename; /* Filename being read */
/* Local data publicly available */
int Weeks = 0; /* How many intervals read in */
char IntvDate[MAX_DATE+1]; /* Date string for current interval */
/* salary units */
int SalFree = 10; /* Free agent salary */
int SalExp = 25;
/* Costs */
int CostRelease = 0;
int CostClaim = 25;
int CostReserve = 10;
int CostExpand = 50;
int CostWClaim = 10; /* Waiver claim */
int CostActive = 10; /* Activate */
int CostFarm = 10; /* Starting player in minors */
/* Local routine prototypes */
static opos_init PROTO( (PDB_PNAME *) );
/* Private data */
/* NONE */
/*
BOOL interval( int tokcnt, char *tokens[] )
Parse the line to get the statistices filename and the date for this
interval. Optionally, the line could end with a filename of an updated
position list.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
#define ARG_INV_DATE 1 /* Date to use */
#define ARG_INV_DFNM 2 /* Data file name */
#define ARG_INV_PFNM 3 /* Position file name (optional) */
BOOL interval ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
int saveLine;
char saveName[20];
BOOL readstat;
if ( tokcnt < ARG_INV_PFNM )
ARGCNT_ERR();
if ( access( tokens[ARG_INV_DFNM], 0 ) != 0 )
{ /* file doesn't exist */
rdb_error( "Interval - Unable to open file: ", tokens[ARG_INV_DFNM] );
return FALSE;
}
VERBOSE( 1, "Week #%d: ", Weeks+1 );
VERBOSE( 1, "Parsing Stat file: %s.\n", tokens[ARG_INV_DFNM] );
#ifdef __TURBOC__
VERBOSE( 3, "Coreleft: %ld.\n", coreleft() );
#endif __TURBOC__
/* Save current input line and filename */
saveLine = InputLine;
strcpy( saveName, InputFilename );
/* copy new file name for error reporting */
strcpy( InputFilename, tokens[ARG_INV_DFNM] );
readstat = pdb_read( Weeks+1, tokens[ARG_INV_DFNM] );
/* Restore error stuff */
InputLine = saveLine;
strcpy( InputFilename, saveName );
if ( !readstat )
{ /* oops, had a problem, give up on it */
rdb_error( "Interval - Problems parsing data in ", tokens[ARG_INV_DFNM] );
return FALSE;
}
Weeks++;
memset( IntvDate, 0, sizeof( IntvDate ) );
if ( strlen( tokens[ARG_INV_DATE] ) > MAX_DATE )
{ /* string too long, complain and truncate */
rdb_error( "Interval - Date string too long: ", tokens[ARG_INV_DATE] );
*(tokens[ARG_INV_DATE]+MAX_DATE) = '\0';
}
strcpy( IntvDate, tokens[ARG_INV_DATE] );
if ( tokcnt > ARG_INV_PFNM )
{ /* Read position info */
VERBOSE( 1, "Parsing Position File: %s.\n", tokens[ARG_INV_PFNM] );
pdb_readpos( tokens[ARG_INV_PFNM], 1 );
}
return TRUE;
}
/*
BOOL oposf( int tokcnt, char *tokens[] )
Read in and parse the position file from the previous year, adding as eligble
positions any played more than 19 games, or, if none, the one with the most games
played.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
#define ARG_OP_PFNM 1 /* Name of position file */
#define ARG_OP_PMIN 2 /* Min # of games required at pos. */
BOOL oposf ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
if ( tokcnt <= ARG_OP_PMIN )
ARGCNT_ERR();
pdb_readpos( tokens[ARG_OP_PFNM], atoi( tokens[ARG_OP_PMIN] ) );
/* now init all the players found in last year's file to zorch=-1 */
pdb_walk( opos_init );
return TRUE;
}
static int opos_init ARGLIST( ( pnameP ) )
FARG( PDB_PNAME *pnameP )
{
PDATA *pdataP; /* Player data */
if ( pnameP == NULL )
return TRUE;
pdataP = pdb_pdata( &pnameP->pn_lname[0], &pnameP->pn_fname[0],
pnameP->batter );
pdataP->zorch = -1;
return TRUE;
}
/*
BOOL slot( int tokcnt, char *tokens[] )
Add a slot description to the list of slots for this rotisserie league.
Also indicate which positions are valid for it.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
#define ARG_SLT_SLOT 1 /* Slot name */
#define ARG_SLT_POS 2 /* First of any valid positions */
BOOL slot ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
int i;
UWORD posmask;
RDB_SLOT slotinf; /* Slot info */
/* Make sure there are plenty of tokens */
if ( tokcnt < ARG_SLT_POS )
ARGCNT_ERR();
if ( Verbose >= 4 )
{ /* Print some ugly stuff. */
fprintf( stderr, "Define slot %s; position list: %s",
tokens[ARG_SLT_SLOT], tokens[ARG_SLT_POS] );
for ( i = ARG_SLT_POS +1; i < tokcnt; ++i )
fprintf( stderr, ", %s", tokens[i] );
fprintf( stderr, "\n" );
}
/* Build slot info */
strncpy( slotinf.slot, tokens[ARG_SLT_SLOT], MAX_SLOT );
slotinf.slot[MAX_SLOT] = NUL;
slotinf.pos = 0;
for( i = ARG_SLT_POS; i < tokcnt; ++i ) {
posmask = pos_to_mask( tokens[i] );
if ( posmask == 0 )
{ /* Not a good position. */
rdb_error( "Unknown position: ", tokens[i] );
}
else
slotinf.pos |= posmask;
}
if ( slotinf.pos == 0 )
{ /* No valid positions found. */
rdb_error( "Slot has no valid positions: ", slotinf.slot );
}
else
{ /* Go ahead and define it. */
slot_add( &slotinf );
}
return TRUE;
}
/*
BOOL bstats ( int tokcnt, char *tokens[] )
Tell which statistics will be used for batters. The defaults are BA, RBI,
HR, and SB.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
BOOL bstats ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
return TRUE;
}
/*
BOOL pstats( int tokcnt, char *tokens[] )
Tell which statistics will be used for pitchers. The defaults are W, Saves,
ERA, and Ratio ((H+BB)/IP)
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
BOOL pstats ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
return TRUE;
}
/*
BOOL cost( int tokcnt, char *tokens[] )
Describe the transactions costs for this league.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
BOOL cost ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
return TRUE;
}
/*
BOOL salunit( int tokcnt, char *tokens[] )
How many pennies in a salary unit. Salaries and costs are all specified in
"salary units", so this is used to format the output.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
BOOL salunit ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
return TRUE;
}
/*
BOOL comment( int tokcnt, char *tokens[] )
Just ignore the rest of the line.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
BOOL comment ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
return TRUE;
}